package com.ruoyi.user.exception;

import com.ruoyi.user.utils.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Lu.F
 * @version 1.0
 * @date 2022/11/11 9:25
 */
@RestControllerAdvice
@Slf4j
public class BizExceptionHandler {

    /**
     * 自定义错误拦截器
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public JsonData handler(Exception e){

        if (e instanceof BizException){
            BizException bizException = (BizException) e;
            log.info("[业务异常：]",bizException);
            return JsonData.buildError(bizException.getMsg());
        }else {
            log.info("[系统异常：]",e);
            return JsonData.buildError(e.getMessage());
        }
    }
}
